package com.ldc.security.handler;

import com.ldc.common.state.StateCode;
import com.ldc.common.utils.ApiResponseUtils;
import com.ldc.model.base.ApiBean;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 用户权限不足
 *
 * @auther liudc
 * @since 2023/6/17
 */
@Component
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ApiBean<String> data = ApiBean.result("", StateCode.INSUFFICIENT_PERMISSIONS);
        ApiResponseUtils.writeObject(response, data);
    }
}
